#include <Arduino.h>

#define EAST 0
#define SOUTH 1
#define WEST 2
#define NORTH 3

#define DELAY 1

//Red load CLK SI
int Pin[4][4] = {
    {32,33,25,26},
    {27,14,12,13},
    {15,2,0,4},
    {16,17,18,19}
};

void Init_595()
{
    for (int i=0;i<4;i++)
    {
        for(int j=0;j<4;j++)
        {
            pinMode(Pin[i][j], OUTPUT);
        }
    }
}

void Write_595(int side, int data)
{

    digitalWrite(Pin[side][2], LOW);
    delay(DELAY);

    for (int i = 0; i < 16; i++)
    {
        if (data % 2 == 1)
        {
            digitalWrite(Pin[side][3], HIGH);
            delay(DELAY);
        }
        else
        {
            digitalWrite(Pin[side][3], LOW);
            delay(DELAY);
        }
        digitalWrite(Pin[side][2], HIGH);
        delay(DELAY);
        digitalWrite(Pin[side][2], LOW);
        delay(DELAY);
        data = data / 2;
    }
}

void Sync_595(int side)
{
    digitalWrite(Pin[side][1], LOW);
    delay(DELAY);
    digitalWrite(Pin[side][1], HIGH);
    delay(DELAY);
    digitalWrite(Pin[side][1], LOW);
    delay(DELAY);
}